<template>
  <div class="app-container">
    <div class="contentBox">
      <div class="searchBox">
        <el-form :model="queryParams" ref="queryRef" :inline="true" @submit.prevent>
          <el-form-item prop="time" style="margin: 0 6px 0 0;">
            <el-date-picker
                v-model="queryParams.time"
                type="datetimerange"
                range-separator="到"
                start-placeholder="开始时间"
                end-placeholder="结束时间"
                format="YYYY/MM/DD HH:mm:ss"
                value-format="YYYY-MM-DD HH:mm:ss"
                @change="handleQuery"
            />
          </el-form-item>
          <el-form-item style="margin: 0 6px 0 0;">
            <el-button class="normalFormBg searchBtn" icon="Search" @click="handleQuery"></el-button>
            <el-button class="normalFormBg searchBtn" icon="Refresh" @click="resetQuery"></el-button>
          </el-form-item>
        </el-form>
      </div>
      <el-row :gutter="10" style="margin: 16px 0;"></el-row>
      <el-table
          v-loading="loading"
          :data="dataList"
          border>
        <el-table-column prop="createTime" label="创建时间" :show-overflow-tooltip="true">
          <template #default="scope">
            <div>{{setTimeFormat(scope.row.createTime)}}</div>
          </template>
        </el-table-column>
        <el-table-column prop="reviewer" label="审核人ID" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="status" label="审核结果" :show-overflow-tooltip="true">
          <template #default="scope">
            <div v-for="(item, index) in meter_company_validatedtype" :key="index" v-show="item.value == scope.row.status">
              <el-tag :type="item.elTagType" v-if="item.elTagType">{{ item.label }}</el-tag>
              <div v-else>{{ item.label }}</div>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" fixed="right">
          <template #default="scope">
            <div class="pageFlex pageFlexCenter">
              <div class="pageFlex pageFlexCenter btnSetBox" @click="handleResults(scope.row.results)">
                <img src="@/assets/images/fileManage.png" class="img">
                <div class="text">查看审核原因</div>
              </div>
            </div>
          </template>
        </el-table-column>
        <template #empty>
          <el-empty description="暂无数据" style="color: var(--el-color-primary);"/>
        </template>
      </el-table>
      <div class="pageFlex pageAlignCenter pageSpaceBetween" style="margin-top: 20px;">
        <div class="totalText">共计 {{total}} 条</div>
        <el-pagination background layout="prev, pager, next" :total="total" :current-page="queryParams.pageNum" :page-size="queryParams.pageSize" @current-change="handleCurrentChange"/>
      </div>
    </div>
    <el-dialog v-model="modalShow" width="870">
      <div class="modalBox">
        <div class="modalBoxContent">
          <el-form
              ref="formRef"
              class="formContent"
              label-width="80"
              :model="form"
              :disabled="true"
          >
            <div class="formContentTop pageFlex pageAlignCenter">
              <div class="line"></div>
              <div class="title">{{ modalTitle }}</div>
            </div>
            <div class="formContentCenter bgFF pageFlexColumn pageAlignCenter">
              <div class="formContentBox" v-html="form.content" v-if="form.content"></div>
              <div class="formContentBox" v-else>暂无</div>
            </div>
          </el-form>
        </div>
      </div>
    </el-dialog>
  </div>
</template>
<script setup>
import { onMounted, computed } from 'vue';
import { searchExamineListApi } from '@/api/gasManage/defaultSetting/companyInfo';
import { useRoute } from 'vue-router';
const { proxy } = getCurrentInstance();
const { meter_company_validatedtype } = proxy.useDict("meter_company_validatedtype");
const route = useRoute();
const queryParams = ref({
  pageNum: 1,
  pageSize: 10,
  manufacturerId: '',
  time: ''
})
const loading = ref(false);
const total = ref(0);
const dataList = ref([]);
const setTimeFormat = computed(()=>{
  return val=>{
    let date = new Date(val);
    return date.toLocaleString();
  }
})
function handleQuery(){
  queryParams.value.pageNum = 1;
  getList();
}
function resetQuery(){
  proxy.resetForm("queryRef");
  handleQuery();
}
async function getList(){
  loading.value = true;
  let params = JSON.parse(JSON.stringify(queryParams.value));
  if(params.time){
    params.startTime = params.time[0];
    params.endTime = params.time[1];
    delete params.time;
  }
  let data = await getExamineListData(params);
  if(data && Array.isArray(data)){
    dataList.value = data;
  }else{
    dataList.value = [];
  }
  loading.value = false;
}
function getExamineListData(params){
  return new Promise(resolve => {
    searchExamineListApi(params).then(res => {
      total.value = Number(res.total);
      resolve(Array.isArray(res.rows) ? res.rows : []);
    }).catch(() => {resolve(false)})
  })
}
function handleCurrentChange(e){
  queryParams.value.pageNum = e;
  getList();
}
const modalShow = ref(false);
const modalTitle = ref('');
const form = ref({
  content: ''
})
function handleResults(results){
  handleModalShow('出库备注');
  form.value.content = results;
}
function handleModalShow(name){
  proxy.resetForm('formRef');
  modalTitle.value = name;
  modalShow.value = true;
}
onMounted(()=>{
  queryParams.value.manufacturerId = route.params.companyId;
  getList();
})
</script>
<style lang='scss' scoped>
@import "@/assets/styles/public.scss";
:deep(.el-input__wrapper){
  background-color: $formBgSet;
  box-shadow: none;
}
.app-container{
  width: 100%;
  min-height: calc(100vh - 66px);
  background: #F8F8F9;
}
.contentBox{
  width: 100%;
  min-height: $pageMinHeight;
  background-color: #FFFFFF;
  border-radius: 5px;
  box-sizing: border-box;
  padding: 12px;
  .searchBtn{
    width: 32px;
    height: 32px;
    font-size: 12px;
    padding: 0;
    border: none;
    margin: 0 6px 0 0px;
  }
  .btnSetBox{
    padding: 0 10px;
    box-sizing: border-box;
    border-right: 1px solid $borderColor;
    cursor: pointer;
    .text{
      height: 16px;
      line-height: 16px;
      color: var(--el-color-primary);
    }
    .img{
      width: 16px;
      height: 16px;
      margin-right: 2px;
    }
    &:last-child{
      border-right: none;
    }
  }
  .totalText{
    height: 22px;
    font-weight: 400;
    font-size: 14px;
    color: #1D2129;
    line-height: 22px;
  }
  .fuTextBox{
    width: 375px;
    :deep(p){
      width: 375px;
    }
    :deep(img){
      width: 375px;
    }
  }
}
.formContentCenter{
  width: 100%;
  .formContentBox{
    width: 750px;
    min-height: 500px;
    padding: 10px 0;
    :deep(p){
      width: 750px;
    }
    :deep(img){
      width: 750px;
    }
  }
}
</style>

